package com.bw.cinema.viewmodel

import android.content.Context
import com.bw.cinema.entity.MutilVideoEntity
import com.bw.cinema.intent.CinemaIntent
import com.bw.cinema.repo.CinemaRepo
import com.bw.lib_miv.BaseViewModel
import com.bw.lib_miv.IUiState
import com.bw.lib_miv.RequestType
import dagger.hilt.android.lifecycle.HiltViewModel
import dagger.hilt.android.qualifiers.ApplicationContext
import javax.inject.Inject


@HiltViewModel
class CinemaViewModel @Inject constructor(
    private val repo: CinemaRepo,
    @ApplicationContext val context: Context
) :
    BaseViewModel<CinemaIntent, IUiState<Any>>() {
    override fun handlerIntent(intent: CinemaIntent) {
        when (intent) {

            //类型
            is CinemaIntent.getMutilType -> {
                httpRequest(repo.getMutilType(), RequestType.MUTIL_TYPE)
            }

            //二级类型
            is CinemaIntent.getSubMutilType -> {
                httpRequest(repo.getSubMutilType(intent.id), RequestType.SUB_MUTIL_TYPE)
            }

            //数据
            is CinemaIntent.getMutilVideo -> {
                httpRequest(
                    repo.getMutilVideo(intent.page, intent.size, intent.id),
                    RequestType.MUTIL_VIDEO
                )
            }

            //猜您喜欢
            is CinemaIntent.getRecommendMutilVideo -> {
                httpRequest(
                    repo.getRecommendMutilVideo(intent.page, intent.size),
                    RequestType.RECOMMEND_MUTIL_VIDEO
                )
            }

            else -> {}
        }
    }


    fun getMutilVideo() = repo.getMutilVideo()

    fun setMutilVideo(entity: MutilVideoEntity) {
        repo.setMutilVideo(entity)
    }

}